<template>
  <div class="strategy">
    <div class="wrapper">
      <div class="title">{{currentItem.title}}</div>
      <div class="time">{{currentItem.time}}</div>
      <div class="img">
        <img mode="aspectFit" :src="currentItem.img" />
      </div>

      <div class="content">
        <strategyContract v-if="currentItem.content === 'contract'" />
        <strategyContract1 v-if="currentItem.content === 'contract1'" />
        <strategyContract2 v-if="currentItem.content === 'contract2'" />
      </div>
    </div>
  </div>
</template>

<script>
import strategyContract from './child/strategyContract'
import strategyContract1 from './child/strategyContract1'
import strategyContract2 from './child/strategyContract2'
import { mapState } from 'vuex'
import { shareMixin } from 'common/js/mixins'

export default {
  mixins: [shareMixin()],
  components: {
    strategyContract,
    strategyContract1,
    strategyContract2
  },
  computed: {
    ...mapState({
      'currentItem': state => state.strategyDetail.currentItem
    })
  },
  mounted () {
    this.initTitle()
  },
  methods: {
    initTitle () {
      const { title } = this.currentItem
      let str = title

      if (title.length > 8) {
        str = `${title.substring(0, 8)}...`
      }

      wx.setNavigationBarTitle({
        title: str
      })
    }
  }
}
</script>

<style lang="scss" scoped>
  @import '~common/scss/color';

  .strategy {
    width: 100%;
    height: 100%;
    position: relative;
    > .wrapper {
      width: 100%;
      height: 100%;
      position: relative;
      padding: 10px;
      box-sizing: border-box;
      > .title {
        font-size: 22px;
        font-weight: 700;
        margin-bottom: 10px;
      }
      > .time {
        font-size: 14px;
        color: lightgray;
        margin-bottom: 10px;
      }
      > .img {
        width: 100%;
        > img {
          width: 100%;
        }
      }
    }
  }
</style>
